package annotation;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/10/24 024.
 */
public class AnnotationProcessor
{
    public static void process(String className) throws ClassNotFoundException
    {
        int testCount = 0, failCount = 0;
        Class clazz = Class.forName(className);
        Object obj = null;
        try
        {
            obj = clazz.newInstance();
        } catch (Exception e)
        {
        }
        Method[] ms = clazz.getDeclaredMethods();
        for (Method m : ms)
        {
            if (m.isAnnotationPresent(Testable.class))
            {
                try
                {
                    m.invoke(obj, new Object[]{});
                    testCount++;
                } catch (Exception e)
                {
                    failCount++;
                    e.printStackTrace();
                }
            }
        }
        System.out.println("本次测试成功" + testCount + "个，失败" + failCount + "");
    }
}
